package cc.dullsky.qrcode;

import java.io.File;

import com.jfinal.core.Controller;

import cc.dullsky.util.QRCodeUtil;

public class QRCodeController extends Controller {
	public void index() {
		String text = getPara("text");
		String logo = getPara("logo");
		try {
			if ("DullSky".equals(logo)) {
				logo = new File("").getCanonicalPath() + "/WebRoot/img/logo100.jpg";
			}
			String imgSrc = QRCodeUtil.getQRCodeBase64(text, logo, 6);
			setAttr("state", true);
			setAttr("imgSrc", imgSrc);
		} catch (Exception e) {
			e.printStackTrace();
			setAttr("state", false);
		} finally {
			renderJson();
		}
	}
}
